package cn.ichiva.service;

import org.springframework.data.redis.core.ListOperations;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class ListService{
    private final ListOperations<String,String> list;

    public ListService(ListOperations<String, String> list) {
        this.list = list;
    }


    public List<String> range(String key, long start, long end) {
        return list.range(key, start, end);
    }


    public void trim(String key, long start, long end) {
        list.trim(key, start, end);
    }


    public Long size(String key) {
        return list.size(key);
    }

    public Long leftPush(String key, String value) {
        return list.leftPush(key, value);
    }

    public Long leftPushAll(String key, Collection<String> values) {
        return list.leftPushAll(key,values);
    }

    public Long leftPushIfPresent(String key, String value) {
        return list.leftPushIfPresent(key, value);
    }

    public Long leftPivotPush(String key, String pivot, String value) {
        return list.leftPush(key, pivot, value);
    }

    public Long rightPush(String key, String value) {
        return list.rightPush(key, value);
    }

    public Long rightPushAll(String key, Collection<String> values) {
        return list.leftPushAll(key, values);
    }

    public Long rightPushIfPresent(String key, String value) {
        return list.rightPushIfPresent(key, value);
    }


    public Long rightPivotPush(String key, String pivot, String value) {
        return list.rightPush(key, pivot, value);
    }


    public void set(String key, long index, String value) {
        list.set(key, index, value);
    }


    public Long remove(String key, long count, String value) {
        return list.remove(key, count, value);
    }


    public String index(String key, long index) {
        return list.index(key, index);
    }


    public String leftPop(String key) {
        return list.leftPop(key);
    }


    public String leftPopTime(String key, long timeout) {
        return list.leftPop(key,timeout, TimeUnit.MILLISECONDS);
    }


    public String rightPop(String key) {
        return list.rightPop(key);
    }


    public String rightPopTime(String key, long timeout) {
        return list.rightPop(key,timeout,TimeUnit.MILLISECONDS);
    }


    public String rightPopAndLeftPush(String sourceKey, String destinationKey) {
        return list.rightPopAndLeftPush(sourceKey, destinationKey);
    }


    public String rightPopAndLeftPushTime(String sourceKey, String destinationKey, long timeout) {
        return list.rightPopAndLeftPush(sourceKey, destinationKey,timeout,TimeUnit.MILLISECONDS);
    }
}
